<?php

define('ACTION_LOGIN', 'login');
define('ACTION_REGISTER', 'register');

switch (TRUE) {
	case (strcmp(ACTION_LOGIN, $action)==0):
		$user = new User();
		if($user->login($email, $password)){ //Good login
			$result = array('status' => intval(NO_ERR), 'result' => $user->tojson());
		} else { //bad login
			$result = array('status' => intval(ERR_LOGIN));
		}
		break;
	case (strcmp(ACTION_REGISTER, $action)==0):
		if(!empty($_GET['name']) && is_string($_GET['name']) && strlen($_GET['name']) >= 3){
			$humanname = $_GET['name'];
			$user = new User();
			if($user->register($email, $password, $humanname)){ //Good register
				$result = $user->tojson();		
				$result = array('status' => intval(NO_ERR), 'result' => $result);
			} else { //bad login
				$result = array('status' => intval(ERR_REGISTER));
			}
		} else {
			$result = array('status' => intval(ERR_GENERAL));
		}
		break;
	default:
		$result = array('status' => intval(ERR_GENERAL));
}


?>